<!--
 * @userName: 湫之恋
 * @Author: Seven
 * @Date: 2020-07-01 16:13:45
 * @LastEditors: Seven
 * @LastEditTime: 2020-07-01 23:05:41
 -->
<template>
  <div id="myChart" :style="{width: '100%', height: '500px'}"></div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
var { mapState, mapActions } = createNamespacedHelpers("estimate");
export default {
  name: "inventory",
  data() {
    return {
      msg: "My Inventory"
    };
  },
  created() {
    this.getEstimateAllAsync();
  },
  mounted(){
    console.log(this.itemNumber)
      this.drawLine();
  },
  watch: {
    "itemNumber"() {
      this.drawLine();
    }
  },
  computed: {
    ...mapState(["itemNumber"]),
    // echartsXData() {
    //   var arr;
    //   arr = this.inventory.allInventory.map(item => {
    //     return item.commodityName;
    //   });
    //   return arr;
    // },
    // echartsYData() {
    //   var arr = [];
    //   arr = this.inventory.allInventory.map(item => {
    //     return Number(item.inventoryNumbers);
    //   });
    //   return arr;
    // }
  },
  methods: {
    ...mapActions(["getEstimateAllAsync"]),
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      //   myChart.clear();
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      //    myChart.clear();

      // 绘制图表
      myChart.setOption(
        {
          title: { text: "评价统计" },
          tooltip: {},
          // x轴
          xAxis: {
            // data: this.echartsXData,
            data: ["巴适","将就","很差"],
            axisLabel: {
              interval: 0,
              rotate: 15, //倾斜度 -90 至 90 默认为0
              margin: 10,
              textStyle: {
                fontWeight: "bolder",
                color: "#000000",
              }
            },
            type: "category"
          },
          // y轴
          yAxis: {
            type: "value"
          },
          // 鼠标放在柱状图上的效果
          series: [
            {
              name: "数量",
              type: "bar",
            //   data: this.echartsYData
              data: [...this.itemNumber]
            }
          ]
        },
        true
      );
    }
  }
};
</script>

<style>
</style>